package com.ml.loan.sys.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ml.loan.common.model.PageResult;
import com.ml.loan.sys.dao.LoginRecordMapper;
import com.ml.loan.sys.model.LoginRecord;
import com.ml.loan.sys.req.LoginRecordSearch;
import com.ml.loan.sys.service.LoginRecordService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author wangfan
 * @since 2019-02-11
 */
@Service
public class LoginRecordServiceImpl extends ServiceImpl<LoginRecordMapper, LoginRecord> implements LoginRecordService {

    @Override
    public PageResult<LoginRecord> listFull(LoginRecordSearch loginRecordSearch) {
        if (StringUtils.isNotBlank(loginRecordSearch.getStartDate())) {
            loginRecordSearch.setStartDate(loginRecordSearch.getStartDate() + " 00:00:00");
        } else {
            loginRecordSearch.setStartDate(null);
        }
        if (StringUtils.isNotBlank(loginRecordSearch.getEndDate())) {
            loginRecordSearch.setEndDate(loginRecordSearch.getEndDate() + " 23:59:59");
        } else {
            loginRecordSearch.setEndDate(null);
        }
        if (StringUtils.isBlank(loginRecordSearch.getAccount())) {
            loginRecordSearch.setAccount(null);
        }
        Page<LoginRecord> iPage = new Page<>(loginRecordSearch.getPage(), loginRecordSearch.getLimit());
        List<LoginRecord> records = baseMapper.listFull(iPage, loginRecordSearch.getStartDate(), loginRecordSearch.getEndDate(), loginRecordSearch.getAccount());
        return new PageResult<>(records, iPage.getTotal());
    }
}
